<template>
  <div class="post-list">
    <article v-for="post in lists" :key="post._id" class="card mb-3 shadow-sm">
      <div class="card-body">
        <h4>
          <router-link :to="{ name: 'postDetail', params: { id: post._id, column: post.column } }">{{ post.title }}</router-link>
        </h4>
        <div class="row my-3 align-items-center">
          <div v-if="post.image && typeof post.image !== 'string'" class="col-3">
            <img :src="post.image.url" :alt="post.title" class="rounded-lg w-50" />
          </div>
          <p :class="{ 'col-9': post.image }">{{ post.excerpt }}</p>
        </div>
        <span class="text-muted">{{ post.createdAt }}</span>
      </div>
    </article>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { type PostProps, ImageProps } from '../store/store';
import { generateFitUrl } from '../helper';
interface Props {
  list: PostProps[]
}
const props = defineProps<Props>()
const lists = computed(() => {
  return props.list.map(list => {
    generateFitUrl(list.image as ImageProps, 200, 110)
    return list
  })
})

</script>

<style scoped>
a {
  color: black;
  text-decoration: none;
}
</style>